home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / LISTMANA / __TESTER / FILELIST.C next >
Text File  |  1989-06-25  |  7KB  |  304 lines

  1. /****                                                                    */
  2. /****    List Testing Code version 1.0 (beta)                            */
  3. /****                                                                    */
  4. /****    All portions of this source code are the property of Jack        */
  5. /****    Herrington.  I, Jack Herrington, give you permission to use        */
  6. /****    use or alter the code in any way that pleases you.  You must    */
  7. /****    however return by whatever means avaliable any improvements        */
  8. /****    you believe significant to Jack Herrington, accepting that        */
  9. /****    these improvements might be contained in later releases of        */
  10. /****    the code. I also grant you permission to remove this header        */
  11. /****    from any file you are WORKING on, as long as you put it back    */
  12. /****    when you're stopped WORKING on it.                                */
  13. /****                                                                    */
  14. /****    Jack Herrington: University Of Miami, Biomedical Computing        */
  15. /****                     1600 N.W. 10th Ave. (R-53)                        */
  16. /****                     (305) 547-6538                                    */
  17. /****                                                                    */
  18.  
  19. /****/
  20. /**** File List Handler */
  21. /****/
  22.  
  23. #include "ListManager.h"
  24. #include "Tester.h"
  25. #include "FileList.h"
  26.  
  27. /****/
  28. /**** File List main dispersion routine */
  29. /****/
  30.  
  31. void FileListHandler(mess,data)
  32. int mess;
  33. unsigned char *data;
  34. {
  35.     switch(mess)
  36.     {
  37.     case MESS_NEW: FileListHandlerNew(); break;
  38.     case MESS_HIT: FileListHandlerHit((int *)data); break;
  39.     case MESS_CLOSE: FileListHandlerClose(); break;
  40.     case MESS_ACTIVATE: FileListHandlerActivate(1); break;
  41.     case MESS_DEACTIVATE: FileListHandlerActivate(0); break;
  42.     case MESS_UPDATE: DrawFakeGrow(Windows[CurWindow].window); break;
  43.     case MESS_GROW: FileListHandlerGrow(); break;
  44.     }
  45. }
  46.  
  47. /****/
  48. /**** Respond to a new message */
  49. /****/
  50.  
  51. void FileListHandlerNew()
  52. {
  53.     FileWindowInfo *fwi;
  54.  
  55.         /**** Create the dialog */
  56.  
  57.     if ( TesterDialogNew(1001,CurHandler) == (-1) ) return;
  58.     SetPort(Windows[CurWindow].window);
  59.  
  60.         /**** Allocate the window record */
  61.  
  62.     TesterAllocateWindowData((long)sizeof(FileWindowInfo));
  63.     TesterLockWindowInfo();
  64.     fwi = (FileWindowInfo *)TesterGetWindowInfo();
  65.  
  66.         /**** Setup the window */
  67.  
  68.     FileListHandlerSetupList(fwi);
  69.  
  70.         /**** Unlock the window information and leave */
  71.  
  72.     TesterUnLockWindowInfo();
  73. }
  74.  
  75. /****/
  76. /**** Setup the list */
  77. /****/
  78.  
  79. void FileListHandlerSetupList(fwi)
  80. FileWindowInfo *fwi;
  81. {
  82.     Handle item;
  83.     Point cellSize,cell;
  84.     Rect box,dBox;
  85.     char charTmp[255];
  86.     int type,x,y,fold;
  87.  
  88.         /**** Get the file and folder icons */
  89.  
  90.     if ( ( fwi->folderIcon = (PicHandle)GetNamedResource('PICT',"\PFolderIcon") ) == 0L ) return;
  91.         DetachResource(fwi->folderIcon);
  92.     if ( ( fwi->fileIcon = (PicHandle)GetNamedResource('PICT',"\PFileIcon") ) == 0L ) return;
  93.         DetachResource(fwi->fileIcon);
  94.  
  95.         /**** Get the box for the list */
  96.  
  97.     GetDItem(Windows[CurWindow].window,ListBox,&type,&item,&box);
  98.     SetDItem(Windows[CurWindow].window,ListBox,type,
  99.         FileListHandlerUpdate,&box);
  100.  
  101.         /**** Move up for the scrollbar and right to fill out the window */
  102.  
  103.     box.top--;
  104.     box.right+=2;
  105.  
  106.         /**** Create the data bounds */
  107.  
  108.     dBox.left = 0; dBox.right = MAX_X;
  109.     dBox.top = 0; dBox.bottom = MAX_Y;
  110.     cellSize.h = 80; cellSize.v = 15;
  111.  
  112.         /**** Create the list */
  113.  
  114.     fwi->nlh = ListNew(&box,&dBox,cellSize,0,
  115.         Windows[CurWindow].window,0,1,0,1);
  116.  
  117.         /**** Setup global cell definitions */
  118.  
  119.     ListSetFrameWidth(0,0,fwi->nlh);
  120.     ListSetGlobalBox(0,fwi->nlh);
  121.     ListSetGlobalFont(0,0,0,fwi->nlh);
  122.     ListSetScrollMethod(incMethod,fwi->nlh);
  123.  
  124.     ListSetColumnWidth(0,20,fwi->nlh);
  125.     ListSetColumnWidth(1,400,fwi->nlh);
  126.     ListSetAddative(-1,-1,fwi->nlh);
  127.  
  128.         /**** Set the cells */
  129.  
  130.     fold = 0;
  131.     for(y=0;y<MAX_Y;y++)
  132.     {
  133.         cell.v = y;
  134.         cell.h = 0;
  135.         ListSetHandler(PictureHandler,cell,fwi->nlh);
  136.         if ( fold == 1 )
  137.         {
  138.             ListSetData((Handle)fwi->folderIcon,cell,fwi->nlh);
  139.             fold = 0;
  140.         }
  141.         else 
  142.         {
  143.             ListSetSelectable(FALSE,cell,fwi->nlh);
  144.             ListSetData((Handle)fwi->fileIcon,cell,fwi->nlh);
  145.             cell.h = 1;
  146.             ListSetSelectable(FALSE,cell,fwi->nlh);
  147.             fold = 1;
  148.         }
  149.  
  150.         cell.h = 1;
  151.         (void)sprintf(charTmp,"%d",y+1);
  152.         ListSetCell((unsigned char *)charTmp,strlen(charTmp),cell,fwi->nlh);
  153.         ListSetHandler(TextBoxHandler,cell,fwi->nlh);
  154.     }
  155.  
  156.         /**** Setup the flags */
  157.  
  158.     ListSetEhancedFlags((NoTrackOutside),fwi->nlh);
  159.     ListDoDraw(TRUE,fwi->nlh);
  160. }
  161.  
  162. /****/
  163. /**** Draw the list */
  164. /****/
  165.  
  166. pascal void FileListHandlerUpdate(Window,ItemNumber)
  167. WindowPtr Window;
  168. int ItemNumber;
  169. {
  170.     FileWindowInfo *fwi;
  171.  
  172.         /**** Lock the window information and update */
  173.  
  174.     SetPort(Window);
  175.     TesterLockWindowInfoWindow(Window);
  176.     fwi = (FileWindowInfo *)TesterGetWindowInfoIndirect(Window);
  177.         ListUpdateWhole(fwi->nlh);
  178.     TesterUnLockWindowInfoWindow(Window);
  179. }
  180.  
  181. /****/
  182. /**** Hit in the window */
  183. /****/
  184.  
  185. void FileListHandlerHit(hit)
  186. int *hit;
  187. {
  188.     FileWindowInfo *fwi;
  189.     Point cell,lpt;
  190.     Rect sizeArea;
  191.     int part;
  192.  
  193.         /**** Lock the window information */
  194.  
  195.     TesterLockWindowInfo();
  196.     fwi = (FileWindowInfo *)TesterGetWindowInfo();
  197.     SetPort(Windows[CurWindow].window);
  198.  
  199.         /**** Disperse according to dialog hit */
  200.  
  201.     if ( *hit == ListBox )
  202.     {
  203.         GetMouse(&lpt);
  204.         part = ListPart(lpt,&cell,fwi->nlh);
  205.         switch(part)
  206.         {
  207.         case inHorizScroll:
  208.         case inVertScroll:
  209.          case inCell:
  210.             ListCickEnhanced(lpt,0,fwi->nlh,ListLineDrag);
  211.             break;
  212.          }
  213.     }
  214.  
  215.         /**** Unlock the window information */
  216.  
  217.     TesterUnLockWindowInfo();
  218. }
  219.  
  220. /****/
  221. /**** Activate or DeActivate the list */
  222. /****/
  223.  
  224. void FileListHandlerActivate(act)
  225. int act;
  226. {
  227.     FileWindowInfo *fwi;
  228.  
  229.     DrawFakeGrow(Windows[CurWindow].window);
  230.  
  231.     TesterLockWindowInfo();
  232.     fwi = (FileWindowInfo *)TesterGetWindowInfo();
  233.         ListActivate(act,fwi->nlh);
  234.     TesterUnLockWindowInfo();
  235. }
  236.  
  237. /****/
  238. /**** Hit in the growRegion of the window */
  239. /****/
  240.  
  241. void FileListHandlerGrow()
  242. {
  243.     FileWindowInfo *fwi;
  244.     Handle item;
  245.     Point MousePT;
  246.     Rect GrowRect,newRect,box;
  247.     long GrowRet;
  248.     int type;
  249.  
  250.         /**** Set the port and get the mouse location */
  251.  
  252.     TesterLockWindowInfo();
  253.     fwi = (FileWindowInfo *)TesterGetWindowInfo();
  254.     GetMouse(&MousePT);
  255.     LocalToGlobal(&MousePT);
  256.  
  257.         /**** Drag the Window grow area */
  258.  
  259.     GrowRect.top=100; GrowRect.bottom=600;
  260.     GrowRect.left=100; GrowRect.right=600;
  261.     if((GrowRet=GrowWindow(Windows[CurWindow].window,MousePT,&GrowRect))==0)return;
  262.     SizeWindow(Windows[CurWindow].window,LoWord(GrowRet),HiWord(GrowRet),0);
  263.  
  264.         /**** Erase the whole thing */
  265.  
  266.     newRect.right = LoWord(GrowRet); newRect.left = 0;
  267.     newRect.bottom = HiWord(GrowRet); newRect.top = 0;
  268.     EraseRect(&newRect);
  269.     InvalRect(&newRect);
  270.  
  271.         /**** Create new userItem dimensions */
  272.  
  273.     GetDItem(Windows[CurWindow].window,ListBox,&type,&item,&box);
  274.     box.top = (-1); box.bottom = HiWord(GrowRet);
  275.     box.left = 0; box.right = LoWord(GrowRet)+2;
  276.     SetDItem(Windows[CurWindow].window,ListBox,type,item,&box);
  277.  
  278.         /**** Use ListSize to define the new list size */
  279.  
  280.     ListSize(box.right-box.left,box.bottom-box.top,fwi->nlh);
  281.  
  282.         /**** Unlock and leave */
  283.  
  284.     TesterUnLockWindowInfo();
  285. }
  286.  
  287. /****/
  288. /**** Close up the window */
  289. /****/
  290.  
  291. void FileListHandlerClose()
  292. {
  293.     FileWindowInfo *fwi;
  294.  
  295.     TesterLockWindowInfo();
  296.     fwi = (FileWindowInfo *)TesterGetWindowInfo();
  297.         ListDispose(fwi->nlh);
  298.     TesterUnLockWindowInfo();
  299.  
  300.     DisposHandle(fwi->folderIcon);
  301.     DisposHandle(fwi->fileIcon);
  302.  
  303.     TesterKillWindow(CurWindow);
  304. }